<!DOCTYPE html>
<html lang="en">
<head>
      <meta charset="UTF-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Welcome Login</title>
      <link rel="stylesheet" href="login.css">
      <script src="request/axios.min.js" type="text/javascript" charset="utf-8"></script>    
</head>
<body>
      <div class="container right-panel-active">
            <!-- Sign In登录 -->
            <div class="container__form container--signup">
                  <form action="#" class="form" id="form1">
                        <h2 class="form__title">Sign In</h2>
                        <input type="text" placeholder="User/Email" class="input" id="loginInput1"/>
                        <!-- <input type="email" placeholder="Email" class="input" /> -->
                        <input type="password" placeholder="Password/EmailCode" class="input" id="loginInput2"/>
                        <a href="#" class="link" onclick="sendEmail()">if you email login,click me send pwd!</a>
                        <a href="#" class="link">Forgot your password?</a>
                        <button class="btn" onclick="userLogin()">Sign In</button>
                  </form>
            </div>
      
            <!-- Register注册 -->
            <div class="container__form container--signin">
                  <form action="#" class="form" id="form2">
                        <h2 class="form__title">Register User</h2>
                        <input type="text" placeholder="UserName" class="input" />
                        <input type="password" placeholder="Password" class="input" />
                        <input type="text" placeholder="Descript" class="input" />                       
                        <button class="btn">Click Register</button>
                  </form>
            </div>
      
            <!-- Overlay -->
            <div class="container__overlay">
                  <div class="overlay">
                        <div class="overlay__panel overlay--left">
                              <button class="btn" id="signIn">Register In</button><br>
                              <button class="btn" id="signIn" onclick="backIndex()">Back Index</button>
                        </div>
                        <div class="overlay__panel overlay--right">
                              <button class="btn" id="signUp">Sign In</button><br>
                              <button class="btn" id="signIn" onclick="backIndex()">Back Index</button>
                        </div>
                  </div>
            </div>
      </div>
      <script type="text/javascript" src="login.js"></script>     
      <script src="request/requestmethod.js"></script>
      <script type="text/javascript">
            function backIndex(){
                 location.href="/";
            }
            // 登录
            function userLogin(){
                  let loginName=document.getElementById('loginInput1').value;
                  let pwd=document.getElementById('loginInput2').value;
                  let user={
                        loginid:loginName,
                        loginpwd:pwd
                  }
                  let url='http://localhost:9999/users/cloud-users/userlogin'
                  axiosPostRequst('post',url,user).then((res)=>{
                        console.log(res);
                        if(res.code === 200){
                              sessionStorage.setItem("token",res.msg);
                              location.href="/";
                              //alert("登录成功");
                        }else{
                              alert(res.msg);
                        }                        
                  })
                  
            }
            //邮件登录
            function sendEmail(){
                  let email=document.getElementById('loginInput1').value;
                  let code=document.getElementById('loginInput2').value;
                  let mailInfo={
                        receiveEmail:email,
                        emailContext:code
                  }
                  let url='http://localhost:9999/sms/sendMail/loginSendCode'
                  axiosPostRequst('post',url,mailInfo).then((res)=>{
                        console.log(res);
                        if(res.code === 200){
                              alert("发送成功");
                              
                        }else{
                              alert(res.msg);
                        }                        
                  })
            }
      </script>
</body>
</html>